Skip to content

fix: await IDLE loop in email channel disconnect to prevent resource leak#22

Open
jeffklassen wants to merge 2 commits intoghostwright:mainfrom
jeffklassen:fix/email-idle-loop-resource-leak
Open

fix: await IDLE loop in email channel disconnect to prevent resource leak#22
jeffklassen wants to merge 2 commits intoghostwright:mainfrom
jeffklassen:fix/email-idle-loop-resource-leak

Conversation

@jeffklassen
Copy link
Copy Markdown
Contributor

Summary

  • Track the IDLE loop promise so disconnect() can await it before calling logout()
  • Move connectionState = "disconnected" before the abort so the loop's while condition exits immediately
  • Fix the mock IDLE in tests to respond to AbortSignal, matching real ImapFlow behavior
  • Add two tests: disconnect-awaits-loop and rapid disconnect/reconnect doesn't leak

Without this fix, a quick disconnect() + connect() can spawn a second IDLE loop that competes for the INBOX mailbox lock with the first.

Test plan

  • All 824 tests pass (822 existing + 2 new)
  • Lint clean
  • Manual: connect email channel, disconnect, reconnect rapidly — verify single IDLE loop in logs

…leak

startIdleLoop() was fire-and-forget, so disconnect() could return
before the loop released the mailbox lock. A rapid disconnect/reconnect
cycle could spawn concurrent IDLE loops competing for the same lock.

Track the loop promise and await it in disconnect(), and set
connectionState before aborting so the loop exits immediately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant